package com.oceanstar.mapper;

import com.baomidou.mybatisplus.core.mapper.Mapper;
import com.oceanstar.Pojo.CheckInRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckInMapper extends Mapper<CheckInRecord> {

    // 插入签到记录
    @Insert("INSERT INTO checkin_table (id, checkin_time, days, points) " +
            "VALUES (#{id}, NOW(), #{days}, #{points})")
    @Options(useGeneratedKeys = true, keyProperty = "checkinId")
    void insertCheckinRecord(CheckInRecord checkinRecord);

    // 根据用户ID查询最新签到记录
    @Select("SELECT * FROM checkin_table WHERE id = #{id} ORDER BY checkin_time DESC LIMIT 1")
    CheckInRecord selectLatestCheckinByUserId(@Param("id") Number id);

    // 查询用户所有签到记录
    @Select("SELECT * FROM checkin_table WHERE id = #{id} ORDER BY checkin_time DESC")
    List<CheckInRecord> selectAllCheckinsByUserId(@Param("id") Number id);

    // 查询用户连续签到天数
    @Select("SELECT days FROM checkin_table WHERE id = #{id} ORDER BY checkin_time DESC LIMIT 1")
    Integer selectContinuousDaysByUserId(@Param("id") Number id);
}